package com.fr.chart.core.glyph;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.ColorInfo;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.Glyph;
import com.fr.chart.math.Plot3D;
import com.fr.chart.math.Projection;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.shape3d.Area3D;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

public class Area3DPlotGlyph extends CategoryPlotGlyph
  implements Plot3D
{
  private static final long serialVersionUID = 823999902188932597L;
  public static final String XML_TAG = "Area3DPlotGlyph";
  private Projection projection = new Projection();
  private int deep;
  private double seriesIntervalPercent;

  public void layoutAxisGlyph()
  {
    super.layoutAxisGlyph();
    layout3DAxisGlyph();
  }

  public void layoutDataSeriesGlyph()
  {
    Object localObject;
    float f2;
    double d1 = getDeep();
    if (d1 == -1.0D)
      d1 = getBounds().getWidth();
    if (isStacked())
    {
      double d2 = d1 / (1.0D + getSeriesIntervalPercent());
      double d4 = -getSeriesIntervalPercent() * d2 * 0.5D;
      int k = 0;
      while (true)
      {
        if (k >= getSeriesSize())
          return;
        DataSeries localDataSeries2 = getSeries(k);
        Area3D localArea3D = new Area3D(d4, d2);
        localDataSeries2.setDrawImpl(localArea3D);
        localArea3D.setProjection(this.projection);
        localArea3D.getColorInfo().dealCondition(getSeriesCollection(), k);
        localObject = new double[localDataSeries2.getDataPointCount()];
        float f1 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(0.0D, 0.0D).getX();
        f2 = (float)getValueAxisGlyph().getPoint2D(0.0D).getY();
        for (int l = 0; l < localDataSeries2.getDataPointCount(); ++l)
        {
          DataPoint localDataPoint1 = localDataSeries2.getDataPoint(l);
          if (localDataPoint1.isValueIsNull())
            break label397:
          double d6 = getDataPointPercentValue(k, l);
          f1 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(l, 0.0D).getX();
          double d8 = 0.0D;
          for (int i4 = k - 1; i4 >= 0; --i4)
            d8 += getDataPointPercentValue(i4, l);
          f2 = (float)(getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d8 + d6).getY());
          localObject[l] = (getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d8).getY());
          if (l == 0)
            localArea3D.moveTo(f1, f2);
          else
            localArea3D.lineTo(f1, f2);
          Point2D localPoint2D2 = this.projection.projectee(f1, f2, d4);
          localDataPoint1.setShape(new Arc2D.Double(localPoint2D2.getX() - 3.0D, localPoint2D2.getY() - 3.0D, 6.0D, 6.0D, 0.0D, 360.0D, 2));
          dealDataPointLabelBounds(localDataPoint1, k);
        }
        for (int i1 = localObject.length - 1; i1 >= 0; --i1)
        {
          if (localDataSeries2.getDataPoint(i1).isValueIsNull())
            label397: break label457:
          localArea3D.lineTo((float)getCategoryAxisGlyph().getPoint2DCateAxis(i1, 0.0D).getX(), (float)localObject[i1]);
        }
        label457: localArea3D.closePath();
        ++k;
      }
    }
    int i = getSeriesSize();
    double d3 = d1 / (1.0D + getSeriesIntervalPercent()) * i;
    for (int j = 0; j < getSeriesSize(); ++j)
    {
      DataSeries localDataSeries1 = getSeries(j);
      double d5 = -getSeriesIntervalPercent() * d3 * (0.5D + j) - d3 * j;
      localObject = new Area3D(d5, d3);
      localDataSeries1.setDrawImpl((Glyph)localObject);
      ((Area3D)localObject).setProjection(this.projection);
      ((Area3D)localObject).getColorInfo().dealCondition(getSeriesCollection(), j);
      double[] arrayOfDouble = new double[localDataSeries1.getDataPointCount()];
      f2 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(0.0D, 0.0D).getX();
      float f3 = (float)getValueAxisGlyph().getPoint2D(0.0D).getY();
      for (int i2 = 0; i2 < localDataSeries1.getDataPointCount(); ++i2)
      {
        DataPoint localDataPoint2 = localDataSeries1.getDataPoint(i2);
        if (localDataPoint2.isValueIsNull())
          break label829:
        double d7 = localDataSeries1.getDataPoint(i2).getValue();
        f2 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(i2, 0.0D).getX();
        f3 = (float)(getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d7).getY());
        arrayOfDouble[i2] = (getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(0.0D).getY());
        if (i2 == 0)
          ((Area3D)localObject).moveTo(f2, f3);
        else
          ((Area3D)localObject).lineTo(f2, f3);
        Point2D localPoint2D1 = this.projection.projectee(f2, f3, d5);
        localDataPoint2.setShape(new Arc2D.Double(localPoint2D1.getX() - 3.0D, localPoint2D1.getY() - 3.0D, 6.0D, 6.0D, 0.0D, 360.0D, 2));
        dealDataPointLabelBounds(localDataPoint2, j);
      }
      for (int i3 = arrayOfDouble.length - 1; i3 >= 0; --i3)
        if (!(localDataSeries1.getDataPoint(i3).isValueIsNull()))
          ((Area3D)localObject).lineTo((float)getCategoryAxisGlyph().getPoint2DCateAxis(i3, 0.0D).getX(), (float)arrayOfDouble[i3]);
      ((Area3D)localObject).closePath();
    }
    label829:
  }

  public void draw(Graphics paramGraphics)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    localGraphics2D.translate(getBounds().getX(), getBounds().getY());
    if (this.valueAxisGlyph != null)
      this.valueAxisGlyph.draw(paramGraphics);
    if (this.categoryAxisGlyph != null)
      this.categoryAxisGlyph.draw(paramGraphics);
    if (this.isStacked)
    {
      i = 0;
      int j = getSeriesSize();
      while (i < j)
      {
        getSeries(i).draw(paramGraphics);
        ++i;
      }
      i = 0;
      j = getSeriesSize();
      while (true)
      {
        if (i >= j)
          break label170;
        getSeries(i).drawLabel(paramGraphics);
        ++i;
      }
    }
    for (int i = getSeriesSize() - 1; i >= 0; --i)
      getSeries(i).draw(paramGraphics);
    for (i = getSeriesSize() - 1; i >= 0; --i)
      getSeries(i).drawLabel(paramGraphics);
    label170: localGraphics2D.translate(-getBounds().getX(), -getBounds().getY());
  }

  public Projection getProjection()
  {
    return this.projection;
  }

  public void setProjection(Projection paramProjection)
  {
    this.projection = paramProjection;
  }

  public void setSeriesIntervalPercent(double paramDouble)
  {
    this.seriesIntervalPercent = paramDouble;
  }

  public double getSeriesIntervalPercent()
  {
    return this.seriesIntervalPercent;
  }

  public void setDeep(int paramInt)
  {
    this.deep = paramInt;
  }

  public int getDeep()
  {
    return this.deep;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Area3DPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("deep", this.deep).attr("seriesIntervalPercent", this.seriesIntervalPercent).end();
    if (this.projection != null)
      this.projection.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("deep")) != null)
          this.deep = Integer.valueOf(str2).intValue();
        if ((str2 = paramXMLableReader.getAttr("seriesIntervalPercent")) != null)
          this.seriesIntervalPercent = Double.valueOf(str2).doubleValue();
      }
      else if (str1.equals("Projection"))
      {
        this.projection = ((Projection)paramXMLableReader.readXMLObject(new Projection()));
      }
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof Area3DPlotGlyph))
      return false;
    Area3DPlotGlyph localArea3DPlotGlyph = (Area3DPlotGlyph)paramObject;
    if (!(super.equals(localArea3DPlotGlyph)))
      return false;
    if (localArea3DPlotGlyph.deep != this.deep)
      return false;
    if (localArea3DPlotGlyph.seriesIntervalPercent != this.seriesIntervalPercent)
      return false;
    return (Equals.equals(localArea3DPlotGlyph.projection, this.projection));
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("projection", this.projection.toJSONObject());
    localJSONObject.put("seriesIntervalPercent", this.seriesIntervalPercent);
    localJSONObject.put("deep", this.deep);
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "Area3DPlotGlyph";
  }
}